@{
    if (!Roles.IsUserInRole("Admin")) {
        Response.SetStatus(HttpStatusCode.Unauthorized);
        return;
    }
    
    var pollId = UrlData[0];
    var chartType = Request["type"];
    var width = Request["width"].AsInt();
    var height = Request["height"].AsInt();
    
    if(chartType.IsEmpty()) {
        chartType = "bar";
	}
        
    if(width == 0) {
        width = 600;
	}

    if(height == 0) {
        height = 400;
	}
        
    // Example of how to use the Polldaddy helper with the WebMatrix Chart helper
    var poll = Polldaddy.GetPoll(pollId);       
    var results = Polldaddy.GetPollResults(pollId);
    
    string[] xValues = results.Select(r => (string)r.text).ToArray();
    int[] yValues = results.Select(r => int.Parse((string)r.total)).ToArray();
    
    var chart = new Chart(width: width, height: height, theme: ChartTheme.Yellow)
        .AddTitle(poll.question)
        .AddSeries("Default", chartType: chartType,
                    xValue: xValues, xField: "Text",
                    yValues: yValues, yFields: "Total")
        .Write();
}
